/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: GlobalExceptionHandler
 * Author:   zhouheng
 * Date:     2019/6/9 11:52
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.web.handler;

import com.zhouh.golden.common.domain.ResponseBo;
import com.zhouh.golden.common.excption.FileDownloadException;
import com.zhouh.golden.common.excption.LimitAccessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 〈全局异常捕获〉<br>
 * 〈〉
 *
 * @author zhouheng
 * @create 2019/6/9
 * @since 1.0.0
 */
@Slf4j
@ControllerAdvice
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {
    @ExceptionHandler(value = LimitAccessException.class)
    @ResponseBody
    public ResponseBo handleLimitAccessException(LimitAccessException e) {
        return ResponseBo.overClocking(e.getMessage());
    }

    @ExceptionHandler(value = FileDownloadException.class)
    @ResponseBody
    public ResponseBo handleFileDownloadException(LimitAccessException e) {
        return ResponseBo.error(e.getMessage());
    }

}